package com.goods.controller.business;

import com.goods.business.service.InStockService;
import com.goods.common.response.ResponseBean;
import com.goods.common.utils.JWTUtils;
import com.goods.common.vo.business.InStockDetailVO;
import com.goods.common.vo.business.InStockVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * Title:
 * Author: fusu
 * DateTime:  2023/3/25
 * Description:
 **/
@Api(tags = "物资模块-入库记录接口")
@RestController
@RequestMapping("/business/inStock")
public class InStockController {
    @Autowired
    private InStockService inStockService;

    @ApiOperation(value = "入库记录列表展示")
    @GetMapping("/findInStockList")
    public ResponseBean findInStockList(@RequestParam(value = "pageNum", required = false) Integer pageNum,
                                        @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                        InStockVO inStockVO) {
        PageVO pageVO = inStockService.findInStockList(pageNum, pageSize, inStockVO);
        return ResponseBean.success(pageVO);
    }

    @ApiOperation(value = "入库记录添加")
    @PostMapping("/addIntoStock")
    public ResponseBean addIntoStock(@RequestBody InStockVO inStockVO,
                                     @RequestHeader("Authorization") String authorization) {
        String username = JWTUtils.getUsername(authorization);
        inStockVO.setOperator(username);
        inStockService.addIntoStock(inStockVO);
        return ResponseBean.success();
    }

    @ApiOperation(value = "入库记录明细")
    @GetMapping("/detail/{inStockId}")
    public ResponseBean getInStockDetail(@PathVariable("inStockId") Long inStockId) {
        InStockDetailVO inStockDetailVO = inStockService.getInStockDetail(inStockId);
        return ResponseBean.success(inStockDetailVO);
    }

    @ApiOperation(value = "通过审核入库")
    @PutMapping("/publish/{inStockId}")
    public ResponseBean publishInStock(@PathVariable("inStockId") Long inStockId) {
        inStockService.publishInStock(inStockId);
        return ResponseBean.success();
    }

    @ApiOperation(value = "加入回收站")
    @PutMapping("/remove/{inStockId}")
    public ResponseBean removeByInStockId(@PathVariable("inStockId") Long inStockId) {
        inStockService.removeByInStockId(inStockId);
        return ResponseBean.success();
    }

    @ApiOperation(value = "删除入库记录")
    @GetMapping("/delete/{inStockId}")
    public ResponseBean deleteByInstockId(@PathVariable("inStockId") Long inStockId) {
        inStockService.deleteByInstockId(inStockId);
        return ResponseBean.success();
    }

    @ApiOperation(value = "还原入库记录")
    @PutMapping("/back/{inStockId}")
    public ResponseBean  backByInStockId(@PathVariable("inStockId")Long inStockId){
        inStockService.backByInStockId(inStockId);
        return ResponseBean.success();
    }
}
